package com.nip.irregularvebsdict.utilities;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.widget.ImageView;

public class ImageAsyncTask extends AsyncTask<String,Void,Drawable> {

	private ImageView imageView;
	
	public ImageAsyncTask(ImageView imageView) {
		super();
		this.imageView = imageView;
	}

	@Override
	protected Drawable doInBackground(String... params) {
		// TODO Auto-generated method stub
		
		try {
			InputStream is = (InputStream) new URL(params[0]).getContent();
			return Drawable.createFromStream(is, "Icon Weather");
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
	}
	
	@Override
	protected void onPostExecute(Drawable result) {
		if(result == null || imageView== null)
		{
			return;
		}
		imageView.setImageDrawable(result);
	}

}
